﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Collections.Specialized;

namespace PartyCraftServer.Web
{
    public class RazorModel
    {
        public HttpListenerContext Context { get; set; }
        public NameValueCollection Query { get; set; }
        public Dictionary<string, object> ViewBag { get; set; }
        public string Url
        {
            get
            {
                return Context.Request.Url.LocalPath;
            }
        }

        public RazorModel(HttpListenerContext Context, NameValueCollection Query)
        {
            this.Context = Context;
            this.Query = Query;
            ViewBag = new Dictionary<string, object>();
        }

        public AuthenticatedEndPoint GetUser()
        {
            if (PartyCraft.WebService.LoggedInUsers.ContainsKey(Context.Request.RemoteEndPoint.Address.ToString()))
            {
                return PartyCraft.WebService.LoggedInUsers[Context.Request.RemoteEndPoint.Address.ToString()];
            }
            else
                return null;
        }

        public void Redirect(string Url)
        {
            Context.Response.RedirectLocation = Url;
            Context.Response.StatusCode = 302;
        }

        public string RenderRazor(string Name)
        {
            return WebService.ExecuteRazor(Name, this);
        }
    }
}
